<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
   <title>FishVideo信息管理平台</title>
   <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
   <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
   <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
  <style>
	.table th{
		text-align:center;
	}
	.table td{
		text-align:center;
	}
	#left{
		width:20%;
		float:left;
	}
	#content{
		width:80%;
		margin-left:20%;
	}
	#info{
		font-size:20px;
	}
	#add{
		float:right;
	}
	 #pageButton{
			width:80%;
			margin-left:10%;
	   }
	   #leftbutton{
			width:50%;
			
	   }
	   #rightbutton{
			width:50%;
			margin-left:50%;
			
	   }
  </style>
   <script>
	 	var istrue=false;
		function test(){
			var s1=document.getElementById("pwd").value;
			var s2=document.getElementById("rpwd").value;
			var s3 =document.getElementById("clogodiv");
			if(s1!=s2){
			s3.innerHTML="错误";
			alert("两次密码输入不一致！");
			s3.style.color="red";
			istrue=false;
			}else if(s1!="" && s1==s2){
			 s3.style.color="blue";
			  s3.innerHTML="正确";
			  istrue=true;
			}
		}
	</script>
</head>
<body>
<?php require_once("control_daohang.php")?>
	<div class="container" id=left>
	<?php require_once("menu.html"); ?>
	</div>
	
	<div id="content">
		<div id="add"><a href="#" data-toggle="modal"  data-target="#register">添加用户&nbsp&nbsp&nbsp</a></div>
		<table class="table">
			<?php
			if(isset($_POST['addUser'])){
				require_once("../utils/upload.php");
				require_once("../utils/db.php");
				$conn=connect();
				$f=false;
				$hob=implode($_POST['like'],",");
				
				$pic_path=GetPic("tx","../user/upload/","0");
				$sql="insert into fishvideo_users values(null,'{$_POST['name']}',md5('{$_POST['pwd']}'),
				'{$_POST['sex']}','{$_POST['bir']}','{$hob}',
				'{$_POST['xl']}','{$_POST['zwjs']}','{$pic_path}');";
				//echo $sql;
				mysql_query($sql,$conn);
				$num=mysql_affected_rows($conn);
				//echo $num;
				if($num<1){
					echo "<script>alert('注册失败！');</script>";
				}
				mysql_close($conn);
			}
			?>
			<?php			
			//所有user信息的输出
			require_once("../utils/db.php");
			$conn=connect();
			$realpath="../user/upload/";
			if(isset($_GET['id'])){//如果删除
				$sql="delete from fishvideo_users where yjl_uid='{$_GET['id']}';";
				//echo $sql;
				if(!mysql_query($sql,$conn)){
					echo "<script>alert('删除失败!');</script>";
				}else{
				unlink($realpath.$_GET['path']);//物理删除
				}
			}
			$sql="select * from fishvideo_users";
			if(isset($_POST['search'])){//查询
				$sql.=" where yjl_uname like '%{$_POST['videoname']}%' ";
			}
			$result=mysql_query($sql,$conn);
			$sumnumber=mysql_num_rows($result);
			//echo $sql;
			//分页
			if(!isset($_GET['page'])){//如果没有
					$page=0;
				}else{
					$page=$_GET['page'];
				}
				$perpage=10;//每页10个
				$pagenumberq=$page*10;
				$sql.=" limit {$pagenumberq},{$perpage}";
				//echo $sql;
				$ym=($pagenumberq+$perpage);
				if($ym>($sumnumber)) $ym=($sumnumber);
			$result=mysql_query($sql,$conn);
			
			$arr=array("yjl_uname","yjl_sex","yjl_birthdate","yjl_hobby","yjl_degree","yjl_intro","yjl_pic");
			$arrName=array("姓名","性别","生日","爱好","学历","自我评价","照片","操作");
			echo "<tr><th>序号</th>";
			for($j=0;$j<count($arrName);$j++){
				echo "<th>{$arrName[$j]}</th>";
			}
			echo "</tr>";
			
			for($j=($pagenumberq+1);$j<=$ym;$j++){
				//解析
				echo "<tr><td>{$j}</td>";
				$row = mysql_fetch_array($result);//得到每一列的结果
				for($i=0;$i<count($arr)-1;$i++){
					$prit=$row[$arr[$i]];
					if(1==$i){
						if($prit==0){
							$prit="男";
						}else{
							$prit="女";
						}
					}
					if(4==$i){
						switch($prit){
							case 0:$prit="高中";break;
							case 1:$prit="大学";break;
							case 2:$prit="研究生";break;
							case 3:$prit="博士";break;
						default:
							$prit="其他学历";
						}
					}
					echo "<td>{$prit}</td>";
				}
				$prit=$row[$arr[$i]];
				echo "<td><img src='{$realpath}{$prit}' width='60px' height='60px'></td>";
				echo "<td><a href='doUpdateUser.php?id={$row['yjl_uid']}'>修改</a> </form> 
				| <a onclick=\"confirm('确定要删除吗')?
location.href='control_user.php?id={$row['yjl_uid']}&path={$prit}':''\" href=\"javascript:;\">删除</a></td>";
				
				echo "</tr>";
			}
			mysql_close($conn);
			?>
		<tr>
<!--分页 -->
	  <div id="dispage">
		<span>
		 <?php
			if($sumnumber%$perpage==0)
			$sumpage=(int)($sumnumber/$perpage);
			else $sumpage=(int)(($sumnumber/$perpage)+1);
				$now =$page+1;
		    echo "共有{$sumnumber}条数据，当前第({$now}/{$sumpage})页";
		?>
		</span>
		<span>
		<?php
		echo "<a href='control_user.php?page=0'>首页</a> ";
		if($page!=0){
		$now = $page-1;
		echo "<a href='control_user.php?page={$now}'>上一页</a> ";
		}
		if($page!=($sumpage-1)){
			$now = $page+1;
		echo "<a href='control_user.php?page={$now}'>下一页</a> ";
		}
		$now=$sumpage-1;
		echo "<a href='control_user.php?page={$now}'>尾页</a>";
		?>
		</span>
	</div>		
	</tr>
</table>
			
	
	<!-- 模态框（Modal）（注册） -->
<div class="modal fade" id="register" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
	   <div class="modal-dialog">
		  <div class="modal-content">
			 <div class="modal-header">
				<button type="button" class="close" 
				   data-dismiss="modal" aria-hidden="true">
					  &times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
				   请填写注册信息
				</h4>
			 </div>
			 <!--登陆主体 -->
			 <div class="modal-body">
		<form role="form"  action="control_user.php" method="post" enctype="multipart/form-data">
		<table class="table" align="center">
		<tr><th>姓名</th><td><input type="text" class="form-control" id="name" name="name"
		required oninvalid="setCustomValidity('请填写姓名')"
					oninput="setCustomValidity('')"></td></tr>
			<tr>
				<th>
				 创建密码：
				</th>
				<td>
					<input type="password" name="pwd" id="pwd" class="form-control" placeholder="password" required oninvalid="setCustomValidity('请填写密码')"
					oninput="setCustomValidity('')">
				</td>
			</tr>
			<tr>
				<th>
				 确认密码：
				</th>
				<td>
					<input type="password" name="rpwd" id="rpwd" class="form-control" required="required" placeholder="password"
					onblur="test()" required oninvalid="setCustomValidity('请再次填写密码')"
					oninput="setCustomValidity('')">
				</td>
				<td>
					<p id="clogodiv">
						
					</p>
				</td>
			</tr>
		<tr><th>性别</th>
		<td colspan="2">
		<input type="radio"  name="sex" value="0"checked>男
		<input type="radio"  name="sex" value="1">女</td></tr>
		<tr><th>生日</th><td><input type="date" id="bir" name="bir" class="form-control"></td></tr>
		<tr><th>爱好</th>
		<td colspan="5">
		<input type="checkbox" name="like[]" checked value="旅游">旅游</radio>
		<input type="checkbox" name="like[]" value="登山">登山</radio>
		<input type="checkbox" name="like[]" value="健身">健身</radio>
		<input type="checkbox" name="like[]" value="上网">上网</radio>
		<input type="checkbox" name="like[]" value="游泳">游泳</radio>
		</td></tr>
		<tr>
		<th>学历</th>
		<td>
		<select name="xl" class="form-control" required oninvalid="setCustomValidity('请选择学历')"
					oninput="setCustomValidity('')">
		  <option  disabled selected>请选择</option>
		  <option value ="0" >高中</option>
		  <option value ="1">大学</option>
		  <option value="2">研究生</option>
		  <option value="3">博士</option>
		</select>
		</td>
		</tr>
		<tr>
		<th>自我介绍</th><td><textarea name="zwjs" class="form-control" rows="3" cols="20"
		placeholder="性格，习惯...."></textarea></td>
		</tr>
		<tr>
		<th>头像</th><td><input type="file" name="tx" class="form-control" ></td>
		</tr>
	</table>
	<div id="pageButton">
		<span id="leftbutton">
		<button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
		</span>
		<span id="rightbutton">
            <button type="submit" name="addUser" class="btn btn-primary">
               注册
            </button>
		</span>
    </div>
	 </form>
	 </div>
	</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</body>
</html>